package com.hxkj.controller;

import com.hxkj.domain.po.Advertisement;
import com.hxkj.service.AdvertisementService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 广告管理
 * <p>
 * Created by chenfangzhou on 2018年9月7日
 */
@RestController
@RequestMapping("/advertisement")
public class AdvertisementController {


    @Autowired
    private AdvertisementService advertisementService;

    /**
     * 获取单条广告信息数据
     *
     * @param advertisement
     * @return 用户信息
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultDataStruct<Advertisement> get(@RequestBody Advertisement advertisement) throws Exception {
        return advertisementService.get(advertisement);
    }

    /**
     * 新增广告信息
     *
     * @param advertisement 广告信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct save(@RequestBody Advertisement advertisement) throws Exception {
        return advertisementService.save(advertisement);
    }


    /**
     * 修改广告信息
     *
     * @param advertisement 广告信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct modify(@RequestBody Advertisement advertisement) throws Exception {
        return advertisementService.modify(advertisement);
    }

    /**
     * 删除广告信息(可删除多条)
     *
     * @param advertisement 广告信息
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct remove(@RequestBody Advertisement advertisement) throws Exception {
        return advertisementService.remove(advertisement);
    }


    /**
     * 获取所有的广告列表,带分页
     *
     * @param parameterDataStruct 广告信息
     * @throws Exception
     */
    @RequestMapping(value = "/getListWithPage", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public ResultPageStruct<Advertisement> getListWithPage(@RequestBody ParameterDataStruct<Advertisement> parameterDataStruct) throws Exception {
        return ResultStructUtils.buildResultPageStruct(advertisementService.getListWithPage(parameterDataStruct.getData() == null ? new Advertisement() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()));
    }


    /**
     * 获取所有的广告列表,不带分页
     *
     * @param advertisement 广告信息
     * @throws Exception
     */
    @RequestMapping(value = "/getList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public List<Advertisement> getList(@RequestBody Advertisement advertisement) throws Exception {
        return advertisementService.getList(advertisement);
    }

    /**
     * @author chenfagnzhou
     * @Description modifySortNum 修改广告排序
     **/
    @RequestMapping(value = "/advertisementColumn/modifysortnum", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    ResultMessageStruct modifySortNum(@RequestBody Map<String, Object> map) throws Exception {
        return advertisementService.modifySortNum(map);
    }


}
